// 页面路径：store/index.js 
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex); //vue的插件机制

// 底部导航栏索引
const tabValue = 0
const userInfo = uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo')) : {};
const isLogin = uni.getStorageSync('userInfo') ? true : false;
const isMember = uni.getStorageSync('isMember') ? uni.getStorageSync('isMember') : false
const member = uni.getStorageSync('member') ?? {};
const user = uni.getStorageSync('user') ? JSON.parse(uni.getStorageSync('user')) : {}
const employee = uni.getStorageSync('employee') ?? '';
const userQrCode = uni.getStorageSync('userQrCode') ?? '';
const employeeIsLogin = uni.getStorageSync('employee') ? true : false;
const employeeInfo = uni.getStorageSync('employeeInfo') ? JSON.parse(uni.getStorageSync('employeeInfo')) : {}

const store = new Vuex.Store({
	state: {
		tabValue, // 导航栏
		userInfo, //存储用户登录的数据
		isLogin, //true   已登录  false  未登录
		addressId: '', // 地址id
		couponId: '', // 优惠券id
		shopCarList: [],
		isMember,
		orderInfo: {}, //订单信息
		circleAddress: '',
		user,
		circleGoods: -1,
		employee,
		employeeIsLogin,
		employeeInfo,
		userQrCode,
		member
	},
	getters: {
		getTabValue: (state) => state.tabValue,
		getUserInfo: (state) => state.userInfo,
		getIsLogin: (state) => {
			// console.log(state.isLogin);
			return state.isLogin
		}
	},
	mutations: {
		setTabValue(state, index) {
			state.tabValue = index
			uni.setStorageSync('tabValue', index)
		},
		setMember(state, member) {
			state.member = member
			uni.setStorageSync('member', member)
		},
		setUserInfo(state, user) {
			state.userInfo = user;
		},
		setIsLogin(state, flag) {
			state.isLogin = flag;
		},
		setAddressId(state, id) {
			state.addressId = id;
		},
		setCouponId(state, id) {
			state.couponId = id;
		},
		setUserQrCode(state, qrCode) {
			state.userQrCode = qrCode;
		},
		setShopCarList(state, list) {
			console.log(list);
			state.shopCarList = list;
		},
		setOrderInfo(state, orderInfo) {
			// console.log(orderInfo);
			state.orderInfo = orderInfo;
		},
		setIsMember(state, flag) {
			state.isMember = flag
		},
		setCircleAddress(state, add) {
			state.circleAddress = add
		},
		setUser(state, userInfo) {
			state.user = userInfo
		},
		setCircleGoods(state, circleGoods) {
			state.circleGoods = circleGoods
		},
		setEmployee(state, employee) {
			state.employee = employee
		},
		setEmployeeIsLogin(state, flag) {
			state.employeeIsLogin = flag
		},
		setEmployeeInfo(state, flag) {
			state.employeeInfo = flag
		},
	}
})

export default store